package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.MenuView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface MenuViewMapper extends JpaRepository<MenuView, Long>, JpaSpecificationExecutor<MenuView> {

    @Query(value = "select p from MenuView p where p.applicationId = :appId and p.menuCode = :menuCode")
    MenuView findByMenuCode(long appId, String menuCode);

    @Query(value = "select p from MenuView p where p.applicationId = :appId and p.menuName = :menuName")
    Collection<MenuView> findListByMenuName(long appId, String menuName);

    @Query(value = "select p from MenuView p where p.applicationId = :appId and p.menuGroup = :menuGroup")
    Collection<MenuView> findListByMenuGroup(long appId, String menuGroup);

    Page<MenuView> findAll(Specification<MenuView> specification, Pageable pageable);
}
